home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Applications… / QuickDraw GX Aware Sample ƒ / Simple Sample GX ƒ / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  5.5 KB  |  232 lines  |  [TEXT/MMCC]

  1. /*********************************************************************
  2.  
  3.     main.c
  4.     
  5.     This file contains the main code, initialization routines, and
  6.     an override for gxPrintingEvent for the QuickDraw GX aware
  7.     sample, "Simple Sample GX."
  8.     
  9.     Additional info can be found in the related develop #19 article,
  10.     "Adding QuickDraw GX Printing to QuickDraw Applications."
  11.  
  12.     Dave Hersey, Apple Developer Technical Support.
  13.     
  14.     ——————— Edit Trail ———————
  15.     
  16.     creation:                                        1/22/94  - dmh
  17.     cleaned up for 2nd draft of develop article:    3/10/94  - dmh
  18.     cleaned up for final:                            4/14/94  - dmh
  19.     
  20. *********************************************************************/
  21.  
  22. #include "Simple Sample.h"
  23.  
  24. Rect                 gWindowRect = {50, 15, 512, 510};    // Our window size.
  25. short                 gAppResRefNum;                        // Our app's resource file refNum.
  26. long                gSleep = 0;                            // Sleep value for WaitNextEvent.
  27. Boolean                gQuitAfterPrinting = true;            // Quit after handling 'pdoc'?
  28. Boolean                gQuitting;                            // Quitting?
  29. Boolean                gSystemSevenIsPresent;                // System 7.0 or later is available?
  30. Boolean                gGXIsPresent;                        // Using QuickDraw GX is available?
  31. Boolean                gInPrintDialog;                        // Is a QDGX print dialog displayed?
  32. gxGraphicsClient    gClient;                            // Our app's QDGX graphics client.
  33.  
  34.  
  35. /************************************************************
  36.   MyInitialize - This routine performs the standard Mac
  37.   toolbox initialization.
  38.  
  39. *************************************************************/
  40.  
  41.  void MyInitialize()
  42.  {
  43.     CursHandle        theCurs; 
  44.     Handle            menuBar;
  45.  
  46. //    We're not quitting, and we don't have a print dialog displayed.
  47.  
  48.     gQuitting = false;
  49.     gInPrintDialog = false;
  50.  
  51. //    Initialize.
  52.  
  53.     InitGraf(&qd.thePort);
  54.     InitFonts();
  55.     InitWindows();
  56.     InitMenus();
  57.     InitCursor();
  58.  
  59. /*
  60.     See what system software is available.  If we don't have
  61.     what we need, bail.
  62. */
  63.     MyCheckConfig();
  64.     
  65.     if (!gSystemSevenIsPresent)
  66.     {
  67.         Alert(r_BadConfig, nil);
  68.         gQuitting = true;
  69.         return;
  70.     }
  71.  
  72. /*
  73.     Change to a watch cursor while we set up our menu bar
  74.     and then install our AppleEvent handlers.
  75. */
  76.     theCurs = GetCursor(watchCursor);
  77.     SetCursor(*theCurs);
  78.  
  79.     menuBar = GetNewMBar(rMenuBar);
  80.  
  81.     if (menuBar)
  82.     {
  83.         SetMenuBar(menuBar);
  84.         DisposHandle(menuBar);
  85.         AddResMenu(GetMHandle(mApple), 'DRVR');
  86.         DrawMenuBar();
  87.         SetCursor(&qd.arrow);
  88.  
  89.         MyDoAEInstallation();
  90.     }
  91. }
  92.  
  93.  
  94. /************************************************************
  95.   MyCheckConfig - This routine sets up our global
  96.   configuration variables based on results from Gestalt.
  97.  
  98. *************************************************************/
  99.  
  100. void MyCheckConfig()
  101. {
  102.     long    sysVersion;
  103.  
  104. //    Get the system version and see if it's 7.0 or later.
  105.  
  106.     gSystemSevenIsPresent = false;
  107.     
  108.     if (Gestalt(gestaltSystemVersion, &sysVersion) == noErr)
  109.         if (sysVersion >= 0x0700) gSystemSevenIsPresent = true;
  110. }
  111.  
  112.  
  113. /************************************************************
  114.   MyInitGXIfPresent - This routine checks to see if the
  115.   QuickDraw GX graphics and printing routines are available,
  116.   and if so, initializes them for us.
  117.  
  118. *************************************************************/
  119.  
  120. void MyInitGXIfPresent()
  121. {
  122.     long        gxVersion, gxPrintVersion;
  123.     MenuHandle    fileMenu;
  124.  
  125. //    Assume GX is NOT present, and then check to see if it is.
  126.  
  127.     gGXIsPresent = false;
  128.  
  129.     if (Gestalt(gestaltGXVersion, &gxVersion) == noErr)
  130.         if (Gestalt(gestaltGXPrintingMgrVersion, &gxPrintVersion) == noErr)
  131.             gGXIsPresent = true;
  132.  
  133. /*
  134.     If QuickDraw GX is available, initialize it.  Otherwise, remove
  135.     the QuickDraw GX options from our File menu.
  136. */
  137.     if (gGXIsPresent)
  138.     {
  139.         gClient = GXNewGraphicsClient(nil, kGraphicsHeapSize, (gxClientAttribute) 0);
  140.         GXEnterGraphics();
  141.         GXInitPrinting();
  142.     }
  143.     else
  144.     {
  145.         fileMenu = GetMHandle(mFile);
  146.         DelMenuItem(fileMenu, iPrintOneCopy);
  147.         DelMenuItem(fileMenu, iCustomPageSetup);
  148.     }
  149. }
  150.  
  151.  
  152. /************************************************************
  153.   MyCleanUpGXIfPresent - This routine de-installs the
  154.   QuickDraw GX graphics and printing routines, if we
  155.   initialized them earlier.
  156.  
  157. *************************************************************/
  158.  
  159. void MyCleanUpGXIfPresent()
  160. {
  161.     if (gGXIsPresent)
  162.     {
  163.         GXExitPrinting();
  164.         GXDisposeGraphicsClient(gClient);
  165.         GXExitGraphics();
  166.     }
  167. }
  168.  
  169.  
  170. /************************************************************
  171.   MyPrintingEventOverride - This routine is an override for
  172.   the gxPrintingEvent message.  This routine is passed
  173.   control when the movable modal print dialogs are displayed
  174.   and we need to update our windows.
  175.  
  176. *************************************************************/
  177.  
  178. OSErr MyPrintingEventOverride(EventRecord *anEvent, Boolean filterEvent)
  179. {
  180.  
  181. /*
  182.     Handle events in whatever way is appropriate.  MyDoEvent is our
  183.     generic event handler.  We don't pass it events that it shouldn't
  184.     handle while print dialogs are displayed.
  185. */
  186.     if (!filterEvent)
  187.         switch (anEvent->what)
  188.         {
  189.             case mouseDown:
  190.             case keyDown:
  191.             case autoKey:
  192.                 break;
  193.             
  194.             default:
  195.                 MyDoEvent(anEvent);
  196.         }
  197.  
  198.     return noErr;
  199. }
  200.  
  201.  
  202. /************************************************************
  203.   main - This is our main routine.  Not much else to say…
  204.  
  205. *************************************************************/
  206.  
  207. void main()
  208. {        
  209.     WindowPtr    wind;
  210.     char        i;
  211.  
  212.     gAppResRefNum = CurResFile();
  213.     MaxApplZone();
  214.     for (i = 1; i <= 6; i++)
  215.         MoreMasters(); 
  216.  
  217. //    Initialize the managers and jump into our event loop.
  218.  
  219.     MyInitialize();    
  220.     MyInitGXIfPresent();
  221.  
  222.     while (!gQuitting)
  223.         MyEventLoop();
  224.  
  225. //    Leaving.  Close all the windows we opened and tear down GX.
  226.  
  227.     while (wind = FrontWindow())
  228.         MyDisposeDocument(MyGetDocPtr(wind));
  229.         
  230.     MyCleanUpGXIfPresent();
  231. }
  232.